package cn.com.nes.site.action.user;

import cn.com.nes.common.util.DBUtils;
import cn.com.nes.site.entity.DataReq;
import cn.com.nes.site.entity.DataRes;
import cn.com.nes.site.entity.PageData;
import cn.com.nes.site.module.service.CallCenterApplyService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 客服中心申请相关接口
 */
@Controller("callcenter")
@RequestMapping("/callcenter")
public class CallCenterApplyAction {

    @Resource
    private CallCenterApplyService callCenterApplyService;

    /**
     * 查询客服中心申请
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping(method = RequestMethod.GET, value = "/getCallCenterApply")
    @ResponseBody
    public PageData getCallCenterApply(HttpServletRequest request, HttpServletResponse response) throws Exception {
        DataRes reqStatus = DBUtils.setRemoteVisit(request, response, true);
        PageData res;
        if (reqStatus.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(reqStatus.getRetCode());
            res.setRetMessage(reqStatus.getRetMessage());
            return res;
        }
        DataReq req = reqStatus.getReq();
        PageData pageData = new PageData();
        try {
            pageData = callCenterApplyService.getCallCenterApply(req);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return pageData;
    }

    /**
     * 保存客服中心申请
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping(method = RequestMethod.POST, value = "/saveCallCenterApply")
    @ResponseBody
    public PageData saveCallCenterApply(HttpServletRequest request, HttpServletResponse response) throws Exception {
        DataRes reqStatus = DBUtils.setRemoteVisit(request, response, true);
        PageData res;
        if (reqStatus.getRetCode() != 0) {
            res = new PageData();
            res.setRetCode(reqStatus.getRetCode());
            res.setRetMessage(reqStatus.getRetMessage());
            return res;
        }
        DataReq req = reqStatus.getReq();
        PageData pageData = new PageData();
        try {
            pageData = callCenterApplyService. saveCallCenterApply(req);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return pageData;
    }

}
